@namespace RazorConsole.Components

@using System.Globalization
@using Microsoft.AspNetCore.Components
@using RazorConsole.Core.Rendering.ComponentMarkup
@using Spectre.Console

<div class="padder"
     data-padding="@PaddingAttribute">
    @ChildContent
</div>

@code {
    private static readonly Padding NoPadding = new(0, 0, 0, 0);

    [Parameter]
    public RenderFragment? ChildContent { get; set; }

    [Parameter]
    public Padding Padding { get; set; } = NoPadding;

    private string? PaddingAttribute
    {
        get
        {
            if (Padding.Left == 0 && Padding.Top == 0 && Padding.Right == 0 && Padding.Bottom == 0)
            {
                return null;
            }

            return string.Join(",",
                Padding.Left.ToString(CultureInfo.InvariantCulture),
                Padding.Top.ToString(CultureInfo.InvariantCulture),
                Padding.Right.ToString(CultureInfo.InvariantCulture),
                Padding.Bottom.ToString(CultureInfo.InvariantCulture));
        }
    }
}
